﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace jQube.Web
{
    internal sealed class NullStream : Stream
    {
        public NullStream(Stream baseStream)
        {
            this.BaseStream = baseStream;
        }

        public Stream BaseStream { get; set; }

        public bool AllowWrites { get; set; }

        public override bool CanRead
        {
            get { return this.BaseStream.CanRead; }
        }

        public override bool CanSeek
        {
            get { return this.CanSeek; }
        }

        public override bool CanWrite
        {
            get { return this.CanWrite; }
        }

        public override long Length
        {
            get { return this.BaseStream.Length; }
        }

        public override long Position
        {
            get { return this.BaseStream.Position; }
            set { this.BaseStream.Position = value; }
        }

        public override void Flush()
        {
            this.BaseStream.Flush();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return this.BaseStream.Read(buffer, offset, count);
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return this.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            this.BaseStream.SetLength(value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            if (this.AllowWrites)
            {
                this.BaseStream.Write(buffer, offset, count);
            }
        }
    }
}
